<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@include file="./common/header.jsp" %>
<body>
<%@ include file="./common/top.jsp"%>
	<div id="mainContainer" class="container">
		
		<a href="#" class="btn btn-primary" id="add_comment_id">为商品增加评论</a>
		
		<div style="margin-top:20px;">
			<table id="comment_table">
		
			</table>
		
		</div>
	</div>

	<script>
		
		$(function() {
			var goodsId =$.request.queryString["id"];
			
			var grid = new jWei.Datagrid({
				renderTo : $("#comment_table"),
				tabWidth:"",
				fieldset:false,
				legendTitle:"",
				url : "../admin/comment/pageList.do?goodsId="+goodsId,
				colModels : [ 
				
				{
					name : "updateDate",
					displayName : "最后更新时间",
				}, 
				{
					name : "comment_username",
					displayName : "用户名称",
				},
				
				{
					name : "comment_grade",
					displayName : "等级"
					
				},
				
				{
					name : "comment_content",
					displayName : "内容"
					
				},
				
				{
					name:"comment_id",
					displayName : "操作",
					handler:function(v,data,td,tr){
						var html = '<a id="edit_id" href="./editComment.jsp?id='+v+'&goodsId='+goodsId+'" data-id="'+v+'" title="编辑" style="margin-right:3px;"><span class="glyphicon glyphicon-edit"></span></a>'+ 
							'<a id="del_id" href="#" class="del" data-id="'+v+'" title="删除"><span class="glyphicon glyphicon-trash"></span></a>';
						td.html(html);
						td.find(".del").unbind("click").click(function(){
							if(!confirm("确定要删除该条评论！")){
								return false;
							}
							var id = $(this).data("id");
							jQuery.ajax({
	          					type : 'Get',
	          					contentType : 'application/json',
	          					url : '../admin/comment/del.do',
	          					data : {
	          						id : id
	          					},
	          					dataType : 'json',
	          					success : function(data) {
	          						if (data.result) {
	        							window.location.href="./commentList.jsp?id="+goodsId;
	          						}else{
	          							alert(data.errorMsg);
	          						}
	          					},
	          					error:function(data){
	          						;
	          					}
							});
							
						});
					}
				}
				
				]
			});
			
			$("#add_comment_id").attr("href","./addComment.jsp?goodsId="+goodsId);
			
		});
		
	</script>

</body>
</html>